﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HZ.BidSystem.Model;
using System.Data;
using System.Data.SqlClient;
using HZ.Data;

namespace HZ.BidSystem.DAL
{
    public class DAL_Company
    {
        public static HZ.BidSystem.Model.Company GetCompanyById(int companyid)
        {
            string sql = "SELECT * FROM TB_Company WHERE CompanyId = @CompanyId";
            IDataParameter para = new SqlParameter("@CompanyId", companyid);
            DataTable dt = HZ.Data.DbHelperFactory.Create().ExecuteTable(CommandType.Text, sql, para);
            if (dt.Rows.Count > 0)
            {

                return DAL_Helper.CommonFill<Company>(dt.Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 判断企业是否有议价品种
        /// </summary>
        /// <param name="companyid"></param>
        /// <returns></returns>
        public static int GetBargain(int companyid)
        {
            string sql = "select CompanyCode_Tb companyid from TB_GoodsBargin ";
            IDataParameter para = new SqlParameter("@CompanyId", companyid);
            DataTable dt = HZ.Data.DbHelperFactory.Create().ExecuteTable(CommandType.Text, sql, para);
            if (dt.Rows.Count > 0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        /// <summary>
        /// 判断企业是否有议价品种
        /// </summary>
        /// <param name="companyid"></param>
        /// <returns></returns>
        public static int GetGoodsBargain(int companyid)
        {
            //判断是否有议价品种  现在Tb_Bargain  已经添加了 CompanyID企业编号标识  不需要在进行关联
            //string sql = "select companyid from Tb_Bargain as a inner join tb_project_bid as b on a.bidid=b.bidid  WHERE CompanyId = @CompanyId ";
            string sql = "select CompanyId_TB from TB_GoodsBargin WHERE CompanyId_TB = @CompanyId ";
            IDataParameter para = new SqlParameter("@CompanyId", companyid);
            DataTable dt = HZ.Data.DbHelperFactory.Create().ExecuteTable(CommandType.Text, sql, para);
            if (dt.Rows.Count > 0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        } 
    }
}
